#include <XBee.h>                //http://code.google.com/p/xbee-arduino/
#define blinkPin 13              //heartbeat LED

/*----------------------------------------------------------------------*
 * SET THE FOLLOWING VARIABLES FOR YOUR PACHUBE ACCOUNT AND XBee!!!     *
 *                                                                      *
 * o Pachube feed number: See the site.                                 *
 * o XBee network coordinator address: Read it out using Digi's         *
 *   X-CTU configuration program, it's also on the bottom of the XBee.  *
 *----------------------------------------------------------------------*/
#define PACHUBE_FEED_NBR ?????   //Pachube feed number to send the data to
XBeeAddress64 coordAddr = XBeeAddress64(0x0013a200, 0x????????);  //Network coordinator forwards data to Pachube

//other global variables
unsigned long msNow, msLast;     //for timing transmissions, etc.
int brightness;                  //brightness reading from photocell

//XBee global variables
#define XBEE_PAYLOAD_LEN 40      //this should agree with the definition in the remote code
XBee xbee = XBee();              //create the XBee object
union {byte B; char C;} xbeePayload[XBEE_PAYLOAD_LEN];
//put your network coordinator's address here!
ZBTxRequest zbTx = ZBTxRequest();
ZBTxStatusResponse txStatus = ZBTxStatusResponse();
ZBRxResponse rx = ZBRxResponse();
ModemStatusResponse msr = ModemStatusResponse();

void setup() {
    pinMode(blinkPin, OUTPUT);
    pinMode(A0, INPUT);             //photocell
    xbee.begin(9600);               //does Serial.begin()
    delay(5000);                    //give the XBee time to associate
}

void loop(void) {
    static boolean blink;
    static int seconds;             //counts seconds so we can transmit once a minute
    
    msNow = millis();
    readXBee();                                  //check for incoming XBee traffic
    if (msNow > msLast + 1000) {                 //once through here per second
        msLast = msNow;
        brightness = readPhotocell(A0);          //read the photocell

        if (seconds++ == 60) {                   //transmit pachube data every 60 sec
            seconds = 0;
            txPachube();
        }
        
        digitalWrite(blinkPin, blink = !blink);  //blink the heartbeat LED
    }
}
